package com.sojson.controller.po;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sojson.entity.po.HelpRecord;
import com.sojson.result.Result;
import com.sojson.service.HelpRecordService;

import io.swagger.annotations.Api;

/**
 * 优惠券助力表控制器
 * 
 * @author liu
 * @date 2021-03-24
 */
@Api(tags = "优惠券助力表管理")
@RestController
@RequestMapping(value = "/helpRecord")
public class HelpRecordController {

    @Resource
    private HelpRecordService helpRecordServiceImpl;

    /**
     * 单条插入
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Object insert(@RequestBody HelpRecord helpRecord) throws SQLException {
        helpRecordServiceImpl.insert(helpRecord);
        return Result.success();
    }

    /**
     * 批量插入
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/insertList", method = RequestMethod.POST)
    public Object insertList(@RequestBody HelpRecord helpRecord) throws SQLException {
        return Result.success(helpRecordServiceImpl.insertList(helpRecord));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/deleteByDto", method = RequestMethod.POST)
    public Object deleteByDto(@RequestBody HelpRecord helpRecord) throws SQLException {
        return Result.success(helpRecordServiceImpl.deleteByDto(helpRecord));
    }

    /**
     * 统计全部数量
     * 
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/countAll", method = RequestMethod.GET)
    public Object countAll() throws SQLException {
        int countAll = helpRecordServiceImpl.countAll();
        return Result.success(countAll);
    }

    /**
     * 查询所有
     * 
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public Object findAll() throws SQLException {
        List<HelpRecord> findAll = helpRecordServiceImpl.findAll();
        return Result.success(findAll);
    }

    /**
     * 根据对象统计数量
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/countByDto", method = RequestMethod.POST)
    public Object countByDto(@RequestBody HelpRecord helpRecord) throws SQLException {
        int countByDto = helpRecordServiceImpl.countByDto(helpRecord);
        return Result.success(countByDto);
    }

    /**
     * 根据对象查询
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/findByDto", method = RequestMethod.POST)
    public Object findByDto(@RequestBody HelpRecord helpRecord) throws SQLException {
        List<HelpRecord> findByDto = helpRecordServiceImpl.findByDto(helpRecord);
        return Result.success(findByDto);
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public Object deleteById(Integer id) throws SQLException {
        helpRecordServiceImpl.deleteById(id);
        return Result.success();
    }

    /**
     * 通过id列表删除(物理删除)
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/deleteByIdList", method = RequestMethod.POST)
    public Object deleteByIdList(@RequestParam("ids[]") List<Integer> ids) throws SQLException {
        return Result.success(helpRecordServiceImpl.deleteByIdList(ids));
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public Object updateById(@RequestBody HelpRecord helpRecord) throws SQLException {
        helpRecordServiceImpl.updateById(helpRecord);
        return Result.success();
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/updateStaticByIdList", method = RequestMethod.POST)
    public Object updateStaticByIdList(@RequestBody HelpRecord helpRecord) throws SQLException {
        return Result.success(helpRecordServiceImpl.updateStaticByIdList(helpRecord));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/updateChangeByIdList", method = RequestMethod.POST)
    public Object updateChangeByIdList(@RequestBody HelpRecord helpRecord) throws SQLException {
        return Result.success(helpRecordServiceImpl.updateChangeByIdList(helpRecord));
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/updatePartialById", method = RequestMethod.POST)
    public Object updatePartialById(@RequestBody HelpRecord helpRecord) throws SQLException {
        helpRecordServiceImpl.updatePartialById(helpRecord);
        return Result.success();
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/updateStaticPartialByIdList", method = RequestMethod.POST)
    public Object updateStaticPartialByIdList(@RequestBody HelpRecord helpRecord) throws SQLException {
        return Result.success(helpRecordServiceImpl.updateStaticPartialByIdList(helpRecord));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/updateChangePartialByIdList", method = RequestMethod.POST)
    public Object updateChangePartialByIdList(@RequestBody HelpRecord helpRecord) throws SQLException {
        return Result.success(helpRecordServiceImpl.updateChangePartialByIdList(helpRecord));
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/findById", method = RequestMethod.GET)
    public Object findById(Integer id) throws SQLException {
        HelpRecord findById = helpRecordServiceImpl.findById(id);
        return Result.success(findById);
    }

    /**
     * 通过id列表查询
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/findByIdList", method = RequestMethod.GET)
    public Object findByIdList(@RequestParam("ids[]") List<Integer> ids) throws SQLException {
        List<HelpRecord> findByIdList = helpRecordServiceImpl.findByIdList(ids);
        return Result.success(findByIdList);
    }

    /**
     * 通过对象查询id列表
     * 
     * @param helpRecord
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/findIdByDto", method = RequestMethod.POST)
    public Object findIdByDto(@RequestBody HelpRecord helpRecord) throws SQLException {
        List<Integer> findIdByDto = helpRecordServiceImpl.findIdByDto(helpRecord);
        return Result.success(findIdByDto);
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     * @throws SQLException
     */
    // @RequestMapping(value = "/clear", method = RequestMethod.POST)
    public Object clear() throws SQLException {
        helpRecordServiceImpl.clear();
        return Result.success();
    }

    /**
     * 根据对象查询头像
     * 
     * @param helpRecord
     * @return
     * @throws IOException 
     */
    @GetMapping(value = "/findThisHeadImg")
    @PreAuthorize("@ss.login()")
    public Object findThisHeadImg(HelpRecord helpRecord) throws IOException {
        List<String> findHeadImg = helpRecordServiceImpl.findThisHeadImg(helpRecord);
        return Result.success(findHeadImg);
    }

}